<template>
  <div>
    <div>警告：销毁账户以后，所有数据都不可恢复，请谨慎操作！</div>
    <div>
      <label>
        现有密码
        <input v-model="password" type="password" />
      </label>
    </div>
    <div>
      <button @click="doDestroy">提交</button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  // data()是一个函数
  // 等同于 function date(){}
  data() {
    return {
      password: null
    };
  },
  methods: {
    doDestroy() {
      let data = new FormData();
      data.append("password", this.password);
      axios.post("/api/user-center/destroy", data).then(response => {
        let result = response.data;
        if (result.code === 1) {
          alert("账户已销户");
          // 返回到登录页面
          this.$router.push("/login");
        } else {
          alert("销户失败: " + result.message);
        }
      });
    }
  }
};
</script>